package com.edmond.jyframe.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.edmond.jyframe.R;
import com.edmond.jyframe.classes.GoodsItem;

import java.util.List;

/**
 * Created by edmond on 17-3-25.
 */

public class HomeAdapter extends BaseHeaderFooterAdapter<GoodsItem> {

    public interface OnItemClickListener{
        void onItemClick(View view,String goodsid,int position);
        void onItemLongClick(View view,String goodsid,int position);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public HomeAdapter(Context context, List<GoodsItem> data) {
        super(context, data);
    }

    @Override
    public  Header initHeader(ViewGroup parent) {
        return new HomeHeader(getInflater().inflate(R.layout.header_home, parent, false));
    }

    @Override
    public void bindHeader(BaseItem item) {

    }

    @Override
    public Footer initFooter(ViewGroup parent) {
        return new HomeFooter(getInflater().inflate(R.layout.footer_home,parent,false));
    }

    @Override
    public void bindFooter(BaseItem item) {

    }

    @Override
    public BaseItem initItem(ViewGroup parent) {
        return new HomeItem(getInflater().inflate(R.layout.item_goods,parent,false));
    }

    @Override
    public void bindItem(BaseItem item, final int position) {
        if(onItemClickListener!=null){
            ((HomeItem)item).itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(v,getData().get(position).getGoodId(),position);
                }
            });
            ((HomeItem)item).itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    onItemClickListener.onItemLongClick(v,getData().get(position).getGoodId(),position);
                    return true;
                }
            });
        }
    }

    class HomeHeader extends Header{
        public HomeHeader(View itemView) {
            super(itemView);
        }

        @Override
        public void initViews(View view) {

        }
    }

    class HomeFooter extends Footer{

        public HomeFooter(View itemView) {
            super(itemView);
        }

        @Override
        public void initViews(View view) {

        }
    }

    class HomeItem extends Item{

        public HomeItem(View itemView) {
            super(itemView);
        }

        @Override
        public void initViews(View view) {

        }
    }
}
